package com.netty.model;

public class LogonReplyPacket extends Packet {
	public int ret;
	public int sessionID;
	
	public byte[] serialize() {
		int totalLength = 16;
		byte[] buffer = new byte[16];
		
		int offset = 0;
		
		
		// copy totallength to buffer
		byte[] totalLengthBuffer = Util.int2bytes(totalLength);
		System.arraycopy(totalLengthBuffer, 0, buffer, offset, 4);
		offset += 4;
		
		// copy packetType to buffer
		byte[] packetType = Util.int2bytes(Service.PACKET_TYPE.S2C_LOGON);
		System.arraycopy(packetType, 0, buffer, offset, 4);
		offset += 4;
		
		// copy ret to buffer
		byte[] retBuffer = Util.int2bytes(ret);
		System.arraycopy(retBuffer, 0, buffer, offset, 4);
		offset += 4;
		
		// copy sessionID to buffer
		byte[] sessionBuffer = Util.int2bytes(sessionID);
		System.arraycopy(sessionBuffer, 0, buffer, offset, 4);
		
		return buffer;
	}
	
	public void unserialize(byte[] buffer) {
		ret = Util.bytes2int(buffer, 8);
		sessionID = Util.bytes2int(buffer, 12);
	}
}
